package com.kfm.servlet;

import com.kfm.util.Contains;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.Console;
import java.io.IOException;
import java.util.Map;

@WebServlet("/outline")
public class OutlineServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");

        Object attribute = getServletContext().getAttribute(Contains.ONLINE_ACCOUNT);

        if (attribute instanceof Map map){
            Object o = map.get(id);

            if (o instanceof HttpSession session){
                session.invalidate();
            }
        }
        resp.sendRedirect("online");
    }
}
